{% extends 'SystemAdminBundle:base:main.0.html.twig' %}

{% block content %}
    {% block main %}

        <form method="post" action="" target="mainframe">
        <div id="floatHead" class="content-tab-wrap">
            <div class="content-tab">
                <div class="content-tab-ul-wrap">
                    <ul>
                        <li><a class="selected" href="javascript:;">管理选项</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="tab-content">
            <dl class="choiceList">
                <dt style="height: 52px;line-height:52px;">
                    选项列表
                </dt>
                <dd>
                    <input type="hidden" name="">
                </dd>
            </dl>
            {% for choice in Choices %}
            <dl class="choiceList">
                <dt style="height: 52px;line-height:52px;">
                    <input class="isAnswer" type="checkbox" name="choiceIsAnswer[{{ choice.id }}]" value="1" {{ choice.isAnswer == 1 ? 'checked="checked"' : "" }}>
                </dt>
                <dd>
                    <div class="toolbar">
                        <div class="l-list">
                            <input style="float: left;" name="choices[{{ choice.id }}]" type="text" class="input normal" value="{{ choice.content }}" datatype="*2-255">
                            <ul class="icon-list">
                                <li><a class="add" href="javascript:;" onclick=""><i></i><span>新增</span></a></li>
                                <li><a class="del" href="javascript:;" onclick="" ><i></i><span>删除</span></a></li>
                                <li><a class="selected" href="javascript:;" onclick=""><i></i><span>设为正确答案</span></a></li>
                            </ul>
                        </div>
                    </div>
                </dd>
            </dl>
            {% endfor %}
        </div>
        {% block submit %}
            <div class="page-footer">
                <div class="btn-wrap">
                    <input type="submit" value="提交保存" id="btnSubmit" class="btn" />
                    <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);" />
                </div>
            </div>
        {% endblock %}
        </form>
    {% endblock %}
    <!-- 需引入-->
    <script type="text/javascript" charset="utf-8" src="{{ asset("bundles/systemadmin/js/laymain.js")}}"></script>
    {% block script %}
        {#---------------------------------------选项管理JS------------------------------------#}
        <script>
            $(".toolbar").on("click",".add", addChoice).on("click",".del", delChoice);
            function addChoice(){
                var a = $(this).parentsUntil(".tab-content").last();
                var row = $("<dl>").addClass("choiceList").append(a.html());
                var rnd = parseInt(Math.random() * 10000000 );
                row.find("dd input").attr("name","choice["+ rnd +"]");
                row.find("dt input").attr("name","choiceIsAnswer["+ rnd +"]");
                a.parent().append(row);
                $(".toolbar")
                        .off("click",".selected", setSelect).on("click",".selected", setSelect)
                        .off("click",".add", addChoice).on("click",".add", addChoice)
                        .off("click",".del", delChoice).on("click",".del", delChoice);
            }
            function delChoice(){
                if ($(".choiceList").size() > 1) {
                    $(this).parentsUntil(".tab-content").last().remove();
                }else{
                    parent.jsdialog("错误提示", "已经是最后一个了，你这样赶紧杀绝好吗？！","");
                }
            }
            function setSelect(){
                $(this).parentsUntil(".tab-content").last().find(".isAnswer").click();
            }

        </script>
        {#---------------------------------------选项管理JS------------------------------------#}

        {% include 'SystemAdminBundle:base:inc.js.article.twig' %}
        {% include 'SystemAdminBundle:base:inc.js.pic.upload.twig' %}
    {% endblock %}
{% endblock %}